package de.fhb.itunes.manager.filewatcher;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import de.fhb.itunes.manager.Config;

public class index_player_xml {

	public void checkDir() {

		try {
			Config config = new Config();
			
			String parent = config.getProperties().getProperty("abs_path");
			String child = "thumbnails";
			File f = new File(parent + child);
			// File[] fileArray = f.listFiles();
			File dir = f;
			boolean istdirectory = f.isDirectory();
			FileWriter xml = new FileWriter(parent + "thumbnail_list.xml");
			if (istdirectory) {
				xml.write("<?xml version=\"1.0ß\" encoding=\"utf-8\"?><thumbnails><config auto_align=\"true\" fullscreen_button=\"false\" folder=\"thumbnails/\" tween_duration=\"0.3\" tn_border_size=\"0\" tn_border_color=\"0xFFFFFF\" tn_alpha=\"true\" x_spacing=\"125\" y_spacing=\"0\" side_tn_count=\"3\"> </config>\n");
				File[] files = dir.listFiles();
				if (files != null) { // Erforderliche Berechtigungen etc. sind
										// vorhanden
					for (int i = 0; i < files.length; i++) {
						if (files[i].isDirectory()) {
							// Es ist ein Ordner
						} else {
							// Es ist ein File
							xml.write("<thumbnail>\n");
							xml.write("<filename>" + files[i].getName()
									+ "</filename> \n");
							xml.write("<target>_blank</target>\n");
							xml.write("</thumbnail>\n");
						}
					}
				}
				xml.write("</thumbnails>");
				xml.close();
			}
		} catch (Exception e) {
			System.err.println(e.getMessage());
		}
	}

}
